package cn.wolfcode.wms.interceptor;

import cn.wolfcode.wms.domain.Employee;
import cn.wolfcode.wms.util.UserContext;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginInterceptor extends HandlerInterceptorAdapter{

    public boolean preHandle(HttpServletRequest request,HttpServletResponse response , Object handler) throws IOException {

        Employee userInSession = UserContext.getCurrentUser();

        if (userInSession == null){
            response.sendRedirect("/login.html");
            return false ;
        }
        return  true;
    }

}
